/**
 * 时间 ： 2014-5-27 下午3:20:51
 * 作者 ： HaiTao
 * 描述 ： 当前类的描述信息
 **/
package com.laitaoo.service.home
{
	import com.laitaoo.event.HomeEvent;
	import com.laitaoo.service.BaseService;
	import com.maclema.mysql.MySqlResponse;
	import com.maclema.mysql.MySqlToken;
	import com.maclema.mysql.ResultSet;
	
	import mx.controls.Alert;
	import mx.rpc.AsyncResponder;

	[RouteEvents]
	[Event(name="treeData", type="com.laitaoo.event.HomeEvent")]
	[Component]
	public class AddYearService extends BaseService
	{
		public function AddYearService()
		{
			super();
		}
		
		public function addYear(year:String):void{

			var mouths:Array = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
			
			var day:int = 0;
			
			var y:int = int(year);
			
			var sqls:Array = [];
			
			for each (var mouth:String in mouths) 
			{
				if(mouth == "一月" || mouth == "三月" || mouth == "五月" || mouth == "七月" || mouth == "八月" || mouth == "十月" || mouth == "十二月"){
					
					day = 31;
					
				}else if(mouth == "四月" || mouth == "六月" || mouth == "九月" || mouth == "十一月"){
					
					day = 30;
					
				}else if(mouth == "二月"){
					
					if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0){
						day = 28;
					}else{
						day = 29;
					}
				}
				getSqls(day,mouth,year,sqls);
			}
			
			for each (var sql:String in sqls) 
			{
				var token:MySqlToken = st.executeQuery(sql);
				
				token.addResponder(new AsyncResponder(loginResultHandler,loginFaultHandler,token));
			}
			
			// 派发加载导航树的事件
			var homeEvent:HomeEvent = new HomeEvent(HomeEvent.TREE_DATA);
			dispatchEvent(homeEvent);
		}
		
		private function getSqls(days:int,mouth:String,year:String,sqls:Array):void{
			
			for(var i:int = 1;i<=days;i++){
				var sql:String = "insert into years(year,mouth,day) values ('"+year+"','"+mouth+"份','"+i+"日')";
				sqls.push(sql);
			}
		}
		private function loginResultHandler(data:Object, token:Object):void{
			
			var rs:MySqlResponse = MySqlResponse(data);
			
		}
		
		private function loginFaultHandler(info:Object, token:Object):void{
			
			
		}
	}
}